/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.shop.service;

import java.util.List;

import com.thinkgem.jeesite.modules.shop.entity.OrderGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.shop.entity.Order;
import com.thinkgem.jeesite.modules.shop.dao.OrderDao;

/**
 * 订单Service
 * @author dby
 * @version 2020-06-30
 */
@Service
@Transactional(readOnly = true)
public class OrderService extends CrudService<OrderDao, Order> {


	@Autowired
	private OrderGoodsService orderGoodsService;

	public Order get(String id) {
		return super.get(id);
	}
	
	public List<Order> findList(Order order) {
		return super.findList(order);
	}
	
	public Page<Order> findPage(Page<Order> page, Order order) {
		return super.findPage(page, order);
	}
	
//	@Transactional(readOnly = false)
//	public void save(Order order) {
//		super.save(order);
//	}


	/*
	 * @Author Zhang Xingliang
	 * @Description 推荐使用此方法
	 * @Date 23:16 2020/7/7
	 **/
	@Transactional(readOnly = false)
	public void save(Order order) {
		super.save(order);
		if(null != order.getOrderGoodsList() && order.getOrderGoodsList().size()>0){
			for (OrderGoods orderGoods :order.getOrderGoodsList()) {
				orderGoods.preInsert();
			}
			orderGoodsService.insertList(order.getOrderGoodsList());
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(Order order) {
		super.delete(order);
	}
	
}